<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="../js/axios.min.js" type="text/javascript"></script>
    <script src="../js/vue.js" type="text/javascript"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <title>我的订单</title>
</head>
<body>
<div id="app">
    <el-container>
        <el-main>
            <!--条件查询-->
            <el-form :inline="true" :model="condition" class="demo-form-inline">
                <el-form-item label="查询">
                    <el-input v-model="condition" placeholder="关键字"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="query">查询</el-button>
                </el-form-item>
            </el-form>
            <!--展示我的私教-->
            <el-table :data="order" border>
                <el-table-column prop="no" label="订单号">
                </el-table-column>
                <el-table-column prop="userName" label="下单人">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间">
                </el-table-column>
                <el-table-column prop="lessonName" label="课程名称">
                </el-table-column>
                <el-table-column prop="lessonTime" label="上课时间">
                </el-table-column>
                <el-table-column prop="note==null? '无':note" label="备注">
                </el-table-column>
                <el-table-column prop="state" label="状态">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button @click="showCheck(scope.row)" type="text" size="small">查看订单</el-button>
                        <el-button v-show="scope.row.state=='已支付待完成'" @click="classOver(scope.row)" type="text"
                                   size="small">上完课了
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页-->
            <div class="block">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageInfo.currentPage"
                        :page-sizes="[3, 4]"
                        :page-size="100"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageInfo.total">
                </el-pagination>
            </div>
        </el-main>
    </el-container>
    <el-dialog
            title="查看订单详情"
            :visible.sync="dialogVisible"
            width="30%">
        <span>订单号：{{check.no}}</span><br>
        <span>下单人：{{check.userName}}</span><br>
        <span>课程：{{check.lessonName}}</span><br>
        <span>创建时间：{{check.createTime}}</span><br>
        <span>上课时间：{{check.lessonTime}}</span><br>
        <span>课时费：{{check.price}}</span><br>
        <span>订单状态：{{check.state}}</span><br>
        <span>备注：{{check.note}}</span><br>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button><br>
            <div>对订单有疑问?&nbsp;&nbsp;<a href="charToUs.html">联系我们</a></div>
  </span>
    </el-dialog>
</div>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                dialogVisible: false,
                pageInfo: {
                    currentPage: 1,// 当前页
                    size: 3,// 每页多少条
                    total: 1// 总条目数
                },
                order: [],
                id: "",
                condition: "",
                check: {}
            }
        },
        methods: {
            // 分页 - 更改每页条数
            handleSizeChange(val) {
                this.pageInfo.size = val
                this.query();
            },
            // 分页 - 更改当前页
            handleCurrentChange(val) {
                this.pageInfo.currentPage = val
                this.query();
            },
            classOver(row) {
                this.id = row.orderId;
                axios.put("/order/finishOder?coachId=", this.id).then(resp => {
                    if (resp.data.code == 200 && resp.status == 200) {
                        alert("操作成功");
                    }
                })
            },
            showCheck(row) {
                console.log(row);
                this.check = row;
                this.dialogVisible = true;
            },
            query() {
                axios.get("/order/myOrder?condition=" + this.condition + "&current=" + this.pageInfo.currentPage + "&size=" + this.pageInfo.size).then(resp => {
                    if (resp.data.code == 200 && resp.status == 200) {
                        this.order = resp.data.data.records;
                        this.pageInfo.total = resp.data.data.total

                    }
                })
            }
        },
        created() {
            this.query();
        }
    })

</script>
</body>
</html>